import Vue from "vue";

Vue.prototype.$toast = function(txt) {
  return this.$createToast({
    txt: txt,
    type: "txt"
  }).show();
};

Vue.prototype.$catch = function(error) {
  if (typeof error === "object") {
    this.$toast(error.message);
  }
};
Vue.prototype.$confirm = function(options) {
  this.$createDialog({
    type: "confirm",
    title: options.title,
    content: options.content,
    confirmBtn: {
      text: "确定",
      active: true,
      disabled: false,
      href: "javascript:;"
    },
    cancelBtn: {
      text: "取消",
      active: false,
      disabled: false,
      href: "javascript:;"
    },
    onConfirm: () => {
      typeof options.confirm == "function" && options.confirm.apply(this);
    },
    onCancel: () => {}
  }).show();
};
Vue.prototype.$alert = function(options) {
  this.$createDialog({
    type: "alert",
    title: options.title,
    content: options.content,
    onConfirm: () => {
      typeof options.confirm == "function" && options.confirm.apply(this);
    }
  }).show();
};

Vue.prototype.$loading = function(flag) {
  this.$createToast({
    txt: "loading",
    mask: true
  }).show();
};
